function compose(...fns) {
  // var res = [1,2,3].reduce((prev, next) => {
  //   console.log(prev, next)
  //   return next + 1;
  // })
  // console.log(res);
  return function(args) {
    let res = fns.reduceRight((prev, next) => {
      let value = prev(args);
      return next.bind(null, value);
    });
    return res();
  }
}

var fn = compose(function a(a) {
  console.log('a')
  return a + '1';
}, function b(b) {
  console.log('b')
  return b+1;
}, function c(c) {
  console.log('c')
  return c+1;
})
console.log(fn(10));